package com.zbkj.admin.controller.platform;

import com.zbkj.common.page.CommonPage;
import com.zbkj.common.result.CommonResult;
import com.zbkj.common.request.PageParamRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import com.zbkj.common.request.CommonBatchRequest;
import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;

import com.zbkj.service.service.MerchantGeneralTypeService;
import com.zbkj.common.model.agent.MerchantGeneralType;
import com.zbkj.common.response.MerchantGeneralTypeDetailResponse;

import com.zbkj.common.request.MerchantGeneralTypeSaveRequest;
import com.zbkj.common.request.MerchantGeneralTypeSearchRequest;
import com.zbkj.common.response.MerchantGeneralTypePageDataResponse;

/**
 * 商户联盟类型管理 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/platform/merchant/general/type")
@Api(tags = "商户联盟类型管理") //配合swagger使用

public class MerchantGeneralTypeController {

    @Autowired
    private MerchantGeneralTypeService merchantGeneralTypeService;

    /**
     * 分页显示商户联盟类型表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author Caiyc
     * @since 2025-08-13
     */
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<MerchantGeneralTypePageDataResponse>> getList(@Validated MerchantGeneralTypeSearchRequest request,
                                                                   @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<MerchantGeneralTypePageDataResponse> merchantGeneralTypeCommonPage = CommonPage.restPage(merchantGeneralTypeService.getList(request, pageParamRequest));
        return CommonResult.success(merchantGeneralTypeCommonPage);
    }

    /**
     * 新增商户联盟类型表
     * @param merchantGeneralTypeSaveRequest 新增参数
     * @author Caiyc
     * @since 2025-08-13
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated MerchantGeneralTypeSaveRequest merchantGeneralTypeSaveRequest) {
        if(merchantGeneralTypeService.create(merchantGeneralTypeSaveRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 删除商户联盟类型表
     * @param id Integer
     * @author Caiyc
     * @since 2025-08-13
     */
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public CommonResult<String> delete(@RequestParam(value = "id") Integer id) {
        if(merchantGeneralTypeService.removeById(id)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 批量删除
     * @param request
     * @return
     * @author Caiyc
     * @since 2025-08-13
     */
    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "批量删除溯源套餐")
    @ApiOperation(value = "批量删除")
    @RequestMapping(value = "/batch/delete", method = RequestMethod.POST)
    public CommonResult<String> batchDelete(@RequestBody @Validated CommonBatchRequest request) {
        if (merchantGeneralTypeService.batchDelete(request.getIdList())) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 修改商户联盟类型表
     * @param merchantGeneralTypeRequest 修改参数
     * @author Caiyc
     * @author Caiyc
     * @since 2025-08-13
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<String> update(@RequestBody @Validated MerchantGeneralTypeSaveRequest merchantGeneralTypeRequest) {
        if (merchantGeneralTypeService.update(merchantGeneralTypeRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 查询商户联盟类型表详情
     * @param id Integer
     * @author Caiyc
     * @since 2025-08-13
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public CommonResult<MerchantGeneralTypeDetailResponse> getDetails(@PathVariable("id") Integer id) {
        return CommonResult.success(merchantGeneralTypeService.getDetails(id));
    }
}



